import {XAXisOption, YAXisOption} from "echarts/types/src/coord/cartesian/AxisModel";
import {SeriesOption} from "echarts";
import {TooltipOption} from "echarts/types/src/component/tooltip/TooltipModel";

let _timer;
export const windowResize = (delay: number, cb: VoidFunction) => {
  _timer && clearTimeout(_timer);
  _timer = setTimeout(() => {
    cb();
  }, delay);
}

export const yAxis = (splitLine: boolean): YAXisOption => ({
  type: 'value',
  axisLabel: {
    fontSize: 14,
    color: '#FFFFFF',
  },
  axisLine: {
    show: true,
    lineStyle: { color: '#283460' }
  },
  axisTick: {
    show: false,
  },
  splitLine: {
    show: splitLine,
    lineStyle:{
      color: ['#bfc0c5'],
      width: 1,
      type: 'solid'
    },
  },
  minInterval: 1,
});
export const xAxis = (data: string[], splitLine: boolean, interval: number | "auto" = "auto"): XAXisOption => ({
  data: data,
  type: 'category',
  axisLabel: {
    fontSize: 14,
    color: '#FFFFFF',
  },
  axisLine: {
    show: true,
    lineStyle: { color: '#283460' }
  },
  axisTick: {
    show: false,
  },
  splitLine: {
    show: splitLine,
    lineStyle:{
      color: ['#bfc0c5'],
      width: 1,
      type: 'solid'
    },
    interval
  },
});

export const series = (
  data: number[],
  color: string,
  name: string,
  unit: string = "个",
  type: any = "bar"
): SeriesOption => ({
  name,
  type,
  tooltip: {
    valueFormatter: (value) => {
      return (value + ' ' + unit);
    }
  },
  itemStyle: {
    color
  },
  barMaxWidth: 50,
  data
});

export const tooltip: TooltipOption = {
  trigger: 'axis',
  axisPointer: {
    type: 'cross',
    label: {
      color: '#fff',
    },
    lineStyle: {color: '#f0f0f0'},
    crossStyle: {color: '#f0f0f0'}
  }
};
